/*manipulations*/

recode treat_dems .=0 if control_secure==1
recode treat_russians .=0 if control_secure==1

/*all three conditions - 
1 cont
2 dems
3 russ
*/

gen cond = control_secure
recode cond .=2 if treat_dems==1
recode cond .=3 if treat_russ==1

/*emotion recodes*/

recode anxious_treat .=0
recode anxious_control .=0
gen anxious = anxious_treat + anxious_control

recode angry_treat .=0
recode angry_control .=0
gen angry = angry_treat + angry_control

recode disgusted_treat .=0
recode disgusted_control .=0
gen disgusted = disgusted_treat + disgusted_control

recode sad_treat .=0
recode sad_control .=0
gen sad = sad_treat + sad_control

recode hopeful_treat .=0
recode hopeful_control .=0
gen hopeful = hopeful_treat + hopeful_control

recode enthusiastic_treat .=0
recode enthusiastic_control .=0
gen enthusiastic = enthusiastic_treat + enthusiastic_control

/*partisans including leaners*/

gen rep = pid
recode rep 2=1 1=0 3=0 4=0
recode rep 0=1 if pid_close == 1

gen dem = pid
recode dem 1=1 2/4=0
recode dem 0=1 if pid_close == 2
/*this yields 290 Republicans (70 leaners) and 567 Democrats (129 leaners)*/

gen ind2 = pid_close
recode ind2 1/2=0 3=1

/*Data and Methods Sample Characteristics*/

tab gender
sum age

/* race */

recode white .=0
recode black .=0
recode hisp .=0
recode asian .=0

tab white
tab black
tab hispanic
tab asian
tab edu

/* have you already voted? */

tab turnout

/*recode imp_concede to correct scale*/
recode imp_concede 4=3 6=4

/*recode government confidence variables to correct scale*/
recode  voting_conf 4=3 5=4
recode media_conf 4=3 5=4
recode presidency_conf 4=3 5=4
recode military_conf 4=3 5=4
recode court_conf 4=3 5=4
recode congress_conf 4=3 5=4


/*ttests and chi2 tests*/

/* Table 2 - manipulation check & fraud likelihood */

/*among democrats */

ttest manipulation if dem==1, by (treat_dems)
ttest manipulation if dem==1, by (treat_russians)

ttest fraud_likely if dem==1, by (treat_dems)
ttest fraud_likely if dem==1, by (treat_russians)

/*among republicans*/

ttest manipulation if rep==1, by (treat_dems)
ttest manipulation if rep==1, by (treat_russians)

ttest fraud_likely if rep==1, by (treat_dems)
ttest fraud_likely if rep==1, by (treat_russians)

/*Table 3 - emotions*/

/*among democrats*/

ttest sad if dem==1, by (treat_dems)
ttest sad if dem==1, by (treat_russians)

ttest anxious if dem==1, by (treat_dems)
ttest anxious if dem==1, by (treat_russians)

ttest disgusted if dem==1, by (treat_dems)
ttest disgusted if dem==1, by (treat_russians)

ttest angry if dem==1, by (treat_dems)
ttest angry if dem==1, by (treat_russians)

ttest enthusiastic if dem==1, by (treat_dems)
ttest enthusiastic if dem==1, by (treat_russians)

ttest hopeful if dem==1, by (treat_dems)
ttest hopeful if dem==1, by (treat_russians)

/*among republicans*/

ttest sad if rep==1, by (treat_dems)
ttest sad if rep==1, by (treat_russians)

ttest anxious if rep==1, by (treat_dems)
ttest anxious if rep==1, by (treat_russians)
ttest anxious if rep==1 & cond~=1, by (cond)

ttest disgusted if rep==1, by (treat_dems)
ttest disgusted if rep==1, by (treat_russians)

ttest angry if rep==1, by (treat_dems)
ttest angry if rep==1, by (treat_russians)

ttest enthusiastic if rep==1, by (treat_dems)
ttest enthusiastic if rep==1, by (treat_russians)

ttest hopeful if rep==1, by (treat_dems)
ttest hopeful if rep==1, by (treat_russians)

/*Figure 1 - electoral confidence*/

ttest electoral_confidence if dem==1, by (treat_dems)
ttest electoral_confidence if dem==1, by (treat_russians)


ttest electoral_confidence if rep==1, by (treat_dems)
ttest electoral_confidence if rep==1, by (treat_russians)

/*Figure 2 - accept results*/

ttest accept_results if dem==1, by (treat_dems)
ttest accept_results if dem==1, by (treat_russians)

ttest accept_results if rep==1, by (treat_dems)
ttest accept_results if rep==1, by (treat_russians)

/*Figure 3 - important to concede*/
ttest imp_concede if dem==1, by (treat_dems)
ttest imp_concede if dem==1, by (treat_russians)

ttest imp_concede if rep==1, by (treat_dems)
ttest imp_concede if rep==1, by (treat_russians)

/*code in Research & Politics paper ends here*/

tab treat_dems party_polarization if dem==1, row chi2
tab treat_russians party_polarization if dem==1, row chi2

tab treat_dems divided_electorate if dem==1, row chi2
tab treat_russians divided_electorate if dem==1, row chi2

tab treat_dems future_polarization if dem==1, row chi2
tab treat_russians future_polarization if dem==1, row chi2

tab treat_dems divided_future if dem==1, row chi2
tab treat_russians divided_future if dem==1, row chi2

ttest trust_electorate if dem==1, by (treat_dems)
ttest trust_electorate if dem==1, by (treat_russians)

ttest voting_conf if dem==1, by (treat_dems)
ttest voting_conf if dem==1, by (treat_russians)

ttest media_conf if dem==1, by (treat_dems)
ttest media_conf if dem==1, by (treat_russians)

ttest presidency_conf if dem==1, by (treat_dems)
ttest presidency_conf if dem==1, by (treat_russians)

ttest military_conf if dem==1, by (treat_dems)
ttest military_conf if dem==1, by (treat_russians)

ttest court_conf if dem==1, by (treat_dems)
ttest court_conf if dem==1, by (treat_russians)

ttest congress_conf if dem==1, by (treat_dems)
ttest congress_conf if dem==1, by (treat_russians)

ttest auth_trump if dem==1, by (treat_dems)
ttest auth_trump if dem==1, by (treat_russians)

ttest auth_clinton if dem==1, by (treat_dems)
ttest auth_clinton if dem==1, by (treat_russians)

ttest blame_dems if dem==1, by (treat_dems)
ttest blame_dems if dem==1, by (treat_russians)

ttest blame_repubs if dem==1, by (treat_dems)
ttest blame_repubs if dem==1, by (treat_russians)

ttest blame_russians if dem==1, by (treat_dems)
ttest blame_russians if dem==1, by (treat_russians)

/*effects among republicans*/

tab treat_dems party_polarization if rep==1, row chi2
tab treat_russians party_polarization if rep==1, row chi2

tab treat_dems divided_electorate if rep==1, row chi2
tab treat_russians divided_electorate if rep==1, row chi2

tab treat_dems future_polarization if rep==1, row chi2
tab treat_russians future_polarization if rep==1, row chi2

tab treat_dems divided_future if rep==1, row chi2
tab treat_russians divided_future if rep==1, row chi2

ttest trust_electorate if rep==1, by (treat_dems)
ttest trust_electorate if rep==1, by (treat_russians)

tab treat_dems turnout_intent if rep==1, row chi2
tab treat_russians turnout_intent if rep==1, row chi2

tab treat_dems next_election_better if rep==1, row chi2
tab treat_russians next_election_better if rep==1, row chi2

tab treat_dems sensitive_lang if rep==1, row chi2
tab treat_russians sensitive_lang if rep==1, row chi2

tab treat_dems spy if rep==1, row chi2
tab treat_russians spy if rep==1, row chi2

tab treat_dems slur if rep==1, row chi2
tab treat_russians slur if rep==1, row chi2

tab treat_dems crackpot if rep==1, row chi2
tab treat_russians crackpot if rep==1, row chi2

tab treat_dems publish if rep==1, row chi2
tab treat_russians publish if rep==1, row chi2

tab treat_dems sat if rep==1, row chi2
tab treat_russians sat if rep==1, row chi2

ttest voting_conf if rep==1, by (treat_dems)
ttest voting_conf if rep==1, by (treat_russians)

ttest media_conf if rep==1, by (treat_dems)
ttest media_conf if rep==1, by (treat_russians)

ttest presidency_conf if rep==1, by (treat_dems)
ttest presidency_conf if rep==1, by (treat_russians)

ttest military_conf if rep==1, by (treat_dems)
ttest military_conf if rep==1, by (treat_russians)

ttest court_conf if rep==1, by (treat_dems)
ttest court_conf if rep==1, by (treat_russians)

ttest congress_conf if rep==1, by (treat_dems)
ttest congress_conf if rep==1, by (treat_russians)

ttest auth_trump if rep==1, by (treat_dems)
ttest auth_trump if rep==1, by (treat_russians)

ttest auth_clinton if rep==1, by (treat_dems)
ttest auth_clinton if rep==1, by (treat_russians)

ttest blame_dems if rep==1, by (treat_dems)
ttest blame_dems if rep==1, by (treat_russians)

ttest blame_repubs if rep==1, by (treat_dems)
ttest blame_repubs if rep==1, by (treat_russians)

ttest blame_russians if rep==1, by (treat_dems)
ttest blame_russians if rep==1, by (treat_russians)

/*effects among independents*/

ttest manipulation if ind2==1, by (treat_dems)
ttest manipulation if ind2==1, by (treat_russians)

ttest fraud_likely if ind2==1, by (treat_dems)
ttest fraud_likely if ind2==1, by (treat_russians)

ttest electoral_confidence if ind2==1, by (treat_dems)
ttest electoral_confidence if ind2==1, by (treat_russians)

ttest accept_results if ind2==1, by (treat_dems)
ttest accept_results if ind2==1, by (treat_russians)

ttest imp_concede if ind2==1, by (treat_dems)
ttest imp_concede if ind2==1, by (treat_russians)


gen consp1 = obama_muslim
recode consp1 1=1 2=0
gen consp2 = trump_pr
recode consp2 1=1 2=0
gen consp3 = clinton_sick
recode consp3 1=1 2=0
gen consp4 = nsa_isis
recode consp4 1=1 2=0
gen consp5 = syria_jews
recode consp5 1=1 2=0
gen consp6 = jail_blacks
recode consp6 1=1 2=0
gen consp7 = bush_katrina
recode consp7 1=1 2=0

gen consp2_scale = consp1 + consp2 + consp3 + consp4 + consp5 + consp6 + consp7
gen consp2_di = consp2_scale
recode consp2_di 0/1 =0 2/8=1

ttest manipulation if consp2_di==1 & dem==1, by (treat_dems)
ttest manipulation if consp2_di==1 & dem==1, by (treat_russians)

ttest fraud_likely if consp2_di==1 & dem==1, by (treat_dems)
ttest fraud_likely if consp2_di==1 & dem==1, by (treat_russians)

ttest electoral_confidence if consp2_di==1 & dem==1, by (treat_dems)
ttest electoral_confidence if consp2_di==1 & dem==1, by (treat_russians)

ttest accept_results if consp2_di==1 & dem==1, by (treat_dems)
ttest accept_results if consp2_di==1 & dem==1, by (treat_russians)

ttest imp_concede if consp2_di==1 & dem==1, by (treat_dems)
ttest imp_concede if consp2_di==1 & dem==1, by (treat_russians)
